<template>
	<div class="teachermanager" style="padding: 40px;">
		<div class="top">
			<div class="leftbox">
					<el-input v-model="teacherId" placeholder="请输入教师编号" :value="teacherId"
					@keyup.enter.native="searchtea"></el-input>
					<el-input v-model="teacherName" placeholder="请输入教师姓名" :value="teacherName"
						@keyup.enter.native="searchtea"></el-input>
					<el-input v-model="teacherPosition" placeholder="请输入教师职称" :value="teacherPosition"
						@keyup.enter.native="searchtea"></el-input>
						<el-button type="primary" icon="el-icon-search" @click.native=" searchteacher" style="background-color:#106ab1 ;">搜索</el-button>
			</div>
			<el-button type="primary" icon="el-icon-circle-plus-outline" @click="addteacher" class="addbtn">添加</el-button>
		</div>
		<div class="teachertable">
			<el-table :data="tableData" style="width: 100%;">
				<el-table-column prop="teacherId" label="教师编号" width="">
				</el-table-column>
				<el-table-column prop="teacherName" label="姓名" width=""></el-table-column>
				<el-table-column prop="teacherPosition" label="教师职称" width="">
				</el-table-column>
				<el-table-column prop="teacherTel" label="联系方式" width=""></el-table-column>
				<el-table-column prop="" label="操作" width="">

					<template slot-scope="scope">
						<!-- <el-button type="danger" @click="delTask(scope.row)">删除</el-button> -->
						<span style="margin: 0 5px; color: green;" class="sp1" @click="changeTeacher(scope.row)">修改</span>

						<span style="color: red;" class="sp1" @click="deleteacher(scope.row)">删除</span>
					</template>
				</el-table-column>
				<el-table-column label="更多" prop="">
					<template slot-scope="scope">
						<img src="../image/切图-右.png" style="cursor: pointer;" alt="" @click="lookdetail(scope.row)">
					</template>
				</el-table-column>
			</el-table>
			<div class="page">
				<el-pagination layout="total,prev, pager, next" :page-count="total" :current-page.sync="pageIndex" @current-change="changepage"
					:page-size="pageSize">
				</el-pagination>
			</div>
			<el-dialog title="" :visible.sync="centerDialogVisible" width="30%" center>
				<b>确认删除</b>
				<span slot="footer" class="dialog-footer">
					<el-button type="primary" @click.native="deleteteacher">确 定</el-button>
					<el-button @click.native="centerDialogVisible = false">取 消</el-button>
				</span>
			</el-dialog>
		</div>
		<router-view></router-view>
	</div>
</template>

<script>
import axios from 'axios'
export default {
	data() {
		return {
			baseUrl: require("../js/baseUrl.js").baseUrl,
			teacherId: "",
			teacherName: "",
			teacherPosition: "",
			centerDialogVisible: false,
			tableData: [],
			pageIndex: 1,//当前第几页
			pageSize: 5, //每页显示五条,
			total: 0,
			teaId: 0
		}
	},
	methods: {
		aaa(abc) {
			// console.log(abc)
		},
		//改变页数
		changepage(v) {
			this.pageIndex = v
			// this.searchteacher()
			if(this.teacherId!="" || this.teacherName!="" || this.teacherPosition!=""){
				this.searchteacher()
			}else{
				this.getTeacherlist()
			}
		},
		//确定删除教师
		deleteacher(index) {
			this.centerDialogVisible = true
			this.teaId = index.teacherId
		},
		deleteteacher() {
			this.centerDialogVisible = !this.centerDialogVisible
			this.deleTea()
		},
		deleTea() {
			this.$http.post(this.baseUrl + "teacher/deleteTeacher", {
				teacherId: this.teaId
			}).then(res => {
				if (res.data.code == 200) {
					this.$message.success("删除成功")
					this.pageIndex=1
					this.searchteacher()
				}
			})
		},
		//显示老师
		getTeacherlist() {
			this.$http.post(this.baseUrl + "teacher/selectTeacher", {
				"pageIndex": this.pageIndex ,//页数
				"pageSize": this.pageSize
			}).then(res => {
				this.total = res.data.data.pageCount
				let data = res.data
				console.log(res)
				if (data.code == 200) {
					console.log(res)
					this.tableData = res.data.data.teacherList
				}
			})
		},
		// gettitleList() {
		// 	this.$http.post(this.baseUrl + "SchoolSys/titleList", {
		// 	}).then(res => {
		// 		res.data.data.forEach(i => {
		// 			this.tableData.forEach(j => {
		// 				if (j.teaTitle == i.titleId) {
		// 					j.teaTitle = i.titleName
		// 				}
		// 			});
		// 		})
		// 	})
		// },
		lookdetail(update) {
			this.$router.push("/teachermanager/teacherdetails?teacherinfoid=" + update.teacherId)
		},
		addteacher() {
			this.$router.push("/teachermanager/addnewteacher")
		},
		changeTeacher(update) {
			sessionStorage.setItem("teacherinfoid",update.teaId)
			this.$router.push("/teachermanager/addnewteacher?teacherinfoid=" + update.teacherId)
		},
		searchtea(){
			this.pageIndex=1
			this.searchteacher()
		},
		searchteacher() {
			this.$http.post(this.baseUrl+"teacher/selectTeacher",{
				pageIndex:this.pageIndex,
				pageSize:this.pageSize,
				teacherId:this.teacherId,
				teacherName:this.teacherName,
				teacherPosition:this.teacherPosition
			}).then(res=>{
				if(res.data.code==200){
					this.tableData = res.data.data.teacherList
					this.total=res.data.data.pageCount
				}else{
					this.tableData=[]
				}
			})
		},
		getappointteacher() {
			// SchoolSys/serchId
		
		},
		//显示老师
		getTeacherlist() {
			this.$http.post(this.baseUrl+"teacher/selectTeacher",{
				pageIndex:this.pageIndex,
				pageSize:this.pageSize,
			}).then(res=>{
				if(res.data.code==200){
					this.tableData = res.data.data.teacherList
					this.total=res.data.data.pageCount
				}
			})
		},
		gettitleList() {
			this.$http.post(this.baseUrl + "SchoolSys/titleList", {
			}).then(res => {
				res.data.data.forEach(i => {
					this.tableData.forEach(j => {
						if (j.teaTitle == i.titleId) {
							j.teaTitle = i.titleName
						}
					});
				})
			})
		},
		lookdetail(update) {
			this.$router.push("/teachermanager/teacherdetails?teacherinfoid=" + update.teacherId)
		},
		addteacher() {
			this.$router.push("/teachermanager/addnewteacher")
		},
		changeTeacher(update) {
			// sessionStorage.setItem("teacherinfoid",update.teaId)
			this.$router.push("/teachermanager/addnewteacher?teacherinfoid=" + update.teacherId)
		}
	},
	//查找教师
	mounted() {
		this.getTeacherlist()
	}
}
</script>
<style lang="less">
.teachermanager{
	.top {
	display: flex;
	position: relative;
}
.top .addbtn{
		position: absolute;
		right: 0;
	}
.teachertable {
	margin-top: 40px;

	.page {
		margin-top: 30px;
	}
}
.top .leftbox {
	display: flex;
	justify-content: space-around;

	.el-input {
		width: 200px;
		margin-right: 20px;
	}
}

.teachertable {
	.sp1 {
		cursor: pointer;

	}

	.el-dialog__body {
		text-align: center !important;
		font-size: 18px;
	}

	.el-table .cell {
		text-align: center;
	}

	.el-table thead {
		color: #333;
	}

	.el-table {
		background: transparent;
		margin: 0;
	}

	.el-table * {
		border: none !important;
	}

	.el-table .el-table__body {
		border-collapse: separate; //分开
		border-spacing: 0 15px;
	}

	.el-table th.el-table__cell {
		background: #f2f6ff;
	}

	.el-pagination {
		text-align: center;
		margin-top: 10px;
	}
}
}

</style>